using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletObj : MonoBehaviour
{
    public float moveSpeed = 50;
    public TankBaseObj fatherObj;
    //特效对象
    public GameObject effObj;

    private void Update()
    {
        transform.Translate(moveSpeed * Time.deltaTime * Vector3.forward);
    }

    //和别人碰撞触发时
    private void OnTriggerEnter(Collider other)
    {
        //子弹设计到不同阵营, 也应该爆炸
        if (other.CompareTag("Map") || 
            (other.CompareTag("Player") && fatherObj.CompareTag("Enemy")) ||
            (other.CompareTag("Enemy") && fatherObj.CompareTag("Player")))
        {
            //判断是否受伤
            TankBaseObj obj = other.GetComponent<TankBaseObj>();
            if (obj != null)
            {
                obj.Wound(fatherObj);
            }
            //子弹销毁时创建一个爆炸特效
            if (effObj != null)
            {
                //创建爆炸特效
                GameObject eff = Instantiate(effObj, transform.position, transform.rotation);
                //修改音效的音量和开启状态
                AudioSource audios = eff.GetComponent<AudioSource>();
                audios.volume = GameDataManager.Instance.musicData.soundValue;
                audios.mute = GameDataManager.Instance.musicData.isOpenSound;
            }
            Destroy(this.gameObject);
        }

    }

    public void setFather(TankBaseObj tank)
    {
        fatherObj = tank;
    }
}
